home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2324 / 2324.xpi / chrome / sessionmanager.jar / content / sessionmanager / sidebar.js < prev    next >
Encoding:
JavaScript  |  2009-08-17  |  6.3 KB  |  167 lines

  1. gSessionManager._onLoad = gSessionManager.onLoad;
  2. gSessionManager.onLoad = function() {
  3.     this._onLoad(true);
  4.     
  5.     // for updating session list
  6.     document.getElementById('session_tree').view = this.treeView;    
  7.         
  8.     // update list on notification
  9.     gSessionManager.mObserverService.addObserver(gSessionManager, "sessionmanager-list-update", false);
  10. }    
  11.  
  12. gSessionManager.onUnload = function() {
  13.     window.removeEventListener("unload", gSessionManager.onUnload, false);
  14.     gSessionManager.mObserverService.removeObserver(gSessionManager, "sessionmanager-list-update");
  15.     gSessionManager.treeView = null;
  16. }
  17.  
  18. gSessionManager.onWindowClose = function() {
  19. }
  20.  
  21. var treeView = {
  22.     defaultChildData: {
  23.         backupFolder: { container: true, open: false, childCount: 0 },
  24.         backupSeparator: { separator: true, row: 1 }
  25.     },
  26.     childData: null,
  27.     visibleData: null,
  28.     
  29.     treeBox: null,
  30.     selection: null,
  31.  
  32.     get rowCount()                     { return this.visibleData.length; },
  33.     setTree: function(treeBox)         { this.treeBox = treeBox; },
  34.     getCellText: function(idx, column) { return this.visibleData[idx]; },
  35.     isContainer: function(idx)         { return this.childData[this.visibleData[idx]].container; },
  36.     isContainerOpen: function(idx)     { return this.childData[this.visibleData[idx]].open; },
  37.     isContainerEmpty: function(idx)    { return this.childData[this.visibleData[idx]].childCount; },
  38.     isSeparator: function(idx)         { return this.childData[this.visibleData[idx]].separator; },
  39.     isSorted: function()               { return false; },
  40.     isEditable: function(idx, column)  { return false; },
  41.  
  42.     getImageSrc: function(idx, column) {},
  43.     getProgressMode : function(idx,column) {},
  44.     getCellValue: function(idx, column) {},
  45.     cycleHeader: function(col, elem) {},
  46.     selectionChanged: function() {},
  47.     cycleCell: function(idx, column) {},
  48.     performAction: function(action) {},
  49.     performActionOnCell: function(action, index, column) {},
  50.     getRowProperties: function(idx, column, prop) {},
  51.     getCellProperties: function(idx, column, prop) {},
  52.     getColumnProperties: function(column, element, prop) {},
  53.     
  54.     getParentIndex: function(idx) {
  55.         if (this.isContainer(idx)) return -1;
  56.         for (var t = idx - 1; t >= 0 ; t--) {
  57.             if (this.isContainer(t)) return t;
  58.         }
  59.     },
  60.     
  61.     getLevel: function(idx) {
  62.         if (this.isContainer(idx)) return 0;
  63.         return 1;
  64.     },
  65.     
  66.     hasNextSibling: function(idx, after) {
  67.         var thisLevel = this.getLevel(idx);
  68.         for (var t = idx + 1; t < this.visibleData.length; t++) {
  69.             var nextLevel = this.getLevel(t)
  70.             if (nextLevel == thisLevel) return true;
  71.             else if (nextLevel < thisLevel) return false;
  72.         }
  73.     },
  74.  
  75.     updateList: function() {
  76.         if (!this.allowUpdate) return;
  77.         this.allowUpdate = false;
  78.         var windowSessions = this.gSessionManager.getWindowSessions();
  79.         var sessions = this.gSessionManager.getSessions();
  80.  
  81.         // clear out existing items from tree
  82.         var children = document.getElementById("sessions");
  83.         var backups = document.getElementById("backup_sessions");
  84.  
  85.         while (backups.childNodes.length) backups.removeChild(backups.childNodes[0]);
  86.         while (children.childNodes.length > 2) children.removeChild(children.childNodes[2]);
  87.  
  88.         // Reset tree view data to default, keep backup container open status.
  89.         if (treeView.childData) treeView.defaultChildData.backupFolder.open = treeView.childData.backupFolder.open;
  90.         delete(treeView.childData);
  91.         delete(treeView.visibleData);
  92.         treeView.childData = treeView.defaultChildData;
  93.         treeView.visibleData = [];
  94.                 
  95.         // Build the tree items from session list
  96.         sessions.forEach(function(aSession, aIx) {
  97.             var treeitem = document.createElement("treeitem");
  98.             var treerow = document.createElement("treerow");
  99.             var name = document.createElement("treecell");
  100.             var windowCount = document.createElement("treecell");
  101.             var tabCount = document.createElement("treecell");
  102.             
  103.             // Properties are used for CSS dispaly stuff
  104.             var property = "";
  105.             if (aSession.autosave) {
  106.                 property = property + aSession.autosave + " ";
  107.             }
  108.             if ((sessions.latestBackUpTime == aSession.timestamp) || (sessions.latestTime == aSession.timestamp)) {
  109.                 property = property + "latest ";
  110.             }
  111.             if ((aSession.name == this.gSessionManager.mPref__autosave_name) || (windowSessions[aSession.name.trim().toLowerCase()])) {
  112.                 property = property + "disabled";
  113.             }
  114.             if (property) name.setAttribute("properties", property);
  115.             
  116.             name.setAttribute("label", aSession.name);
  117.             windowCount.setAttribute("label", aSession.windows);
  118.             tabCount.setAttribute("label", aSession.tabs);
  119.             
  120.             treerow.appendChild(name);
  121.             treerow.appendChild(windowCount);
  122.             treerow.appendChild(tabCount);
  123.             
  124.             treeitem.appendChild(treerow);
  125.             
  126.             if (aSession.backup) backups.appendChild(treeitem);
  127.             else children.appendChild(treeitem);
  128.             
  129.             // Add session filename to TreeView data for easy lookup
  130.             treeView.childData[aSession.name] = { filename: aSession.fileName, backup: aSession.backup  };
  131.             if (aSession.backup) {
  132.                 treeView.childData.backupFolder.childCount++;
  133.                 // if backup Folder not in display list, add it and the separator
  134.                 if (!treeView.visibleData.backupFolder) {
  135.                     treeView.visibleData.unshift("backupSeparator");
  136.                     treeView.visibleData.unshift("backupFolder");
  137.                 }
  138.                 if (treeView.childData.backupFolder.open) {
  139.                     treeView.visibleData.splice(treeView.childData.backupSeparator.row++, 0, aSession.name);
  140.                 }
  141.             }
  142.             else {
  143.                 treeView.visibleData.push(aSession.name);
  144.             }
  145.         }, this);
  146.         
  147.         document.getElementById("backup_container").hidden = (backups.childNodes.length == 0);
  148.         document.getElementById("backup_separator").hidden = (backups.childNodes.length == 0);
  149.         
  150.         this.allowUpdate = true;
  151.     },
  152.     
  153.     handleEvent: function(aEvent) {
  154.         // ignore non-enter key presses and right clicks
  155.         if (((aEvent.type == "keypress") && (aEvent.keyCode != KeyEvent.DOM_VK_RETURN)) ||
  156.             ((aEvent.type == "click") && (aEvent.button == 2))) {
  157.             return;
  158.         }
  159.         
  160.         var index = document.getElementById("session_tree").currentIndex;
  161.         var filename = treeView.getCellText(index);
  162.         dump("index = " + index + ", filename = " + filename + "\n");
  163.         
  164.         //this.gSessionManager.load(filename, (event.shiftKey && (event.ctrlKey || event.metaKey))?"overwrite":(event.shiftKey)?"newwindow":(event.ctrlKey || event.metaKey)?"append":"");
  165.     }
  166. }
  167.